package com.hmall.order.service.impl;

import com.hmall.feign.client.ItemClient;
import com.hmall.item.pojo.Item;
import com.hmall.order.dto.OrderDto;
import com.hmall.order.mapper.OrderDetailMapper;
import com.hmall.order.pojo.OrderDetail;
import com.hmall.order.service.OrderDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class OrderDetailServiceImpl implements OrderDetailService {
    @Autowired
    ItemClient itemClient;
    @Autowired
    OrderDetailMapper orderDetailMapper;
    @Override
    public void insertOrderDetail(OrderDto order, Long id) {
        OrderDetail orderDetail=new OrderDetail();
        orderDetail.setOrderId(id);
        orderDetail.setItemId(order.getItemId());
        orderDetail.setNum(order.getNum());
        Item item=itemClient.queryItemById(order.getItemId());
        orderDetail.setName(item.getName());
        orderDetail.setSpec(item.getSpec());
        orderDetail.setImage(item.getImage());
        orderDetail.setCreateTime(new Date());
        orderDetail.setPrice(item.getPrice());
        orderDetailMapper.insert(orderDetail);



    }
}
